package service;

import com.google.gson.Gson;
import gold.vo.TreeNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by fanzhenyu02 on 2020/2/27.
 */
@Slf4j
public class Runner {

    public static void main(String[] args) throws Exception {
        Runner runner = new Runner();
        runner.run();
    }

    public void run() throws Exception {

        final String content = readToString("/Users/zhfan/Downloads/vo.txt");
        Gson gson = new Gson();
        Map<String, Object> map = new HashMap<String, Object>();
        map = gson.fromJson(content, map.getClass());
        final List<Map<String, Object>> list = (List<Map<String, Object>>) (map.get("list"));
        for (Map<String, Object> stringObjectMap : list) {
            if ("Illegal".equalsIgnoreCase((String) stringObjectMap.get("ruleType")) && "ENABLED".equalsIgnoreCase((String) stringObjectMap.get("status"))) {
                List<Map<String, Object>> extendAttributesList = (List<Map<String, Object>>) stringObjectMap.get("ruleExtendAttributesList");
                for (Map<String, Object> objectMap : extendAttributesList) {
                    if ("priority".equalsIgnoreCase((String) objectMap.get("key"))) {
                        System.out.println((String) stringObjectMap.get("ruleGroup") + "," + (String) objectMap.get("value"));
                    }
                }
            }
        }

//        System.out.println(Long.MAX_VALUE);


//        String tx = "\ud68cl\ub86d\ud488";
//        System.out.println(tx);

//        Map<Integer, Integer> cnt = new HashMap<>();
//        for (int i = 0; i < 1000; i++) {
//            int randomCDN = (int) (Math.random() * 15) + 1;
//            cnt.put(randomCDN, cnt.getOrDefault(randomCDN, 0) + 1);
//        }
//
//        System.out.println(cnt);


//        String startDt = "20210708";
//
//        DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//        long curTimeMills = System.currentTimeMillis(), visitingTime = sdf.parse(startDt).getTime();
//        int maxVisitingDayCounter = 30;
//
//        while (visitingTime <= curTimeMills && maxVisitingDayCounter-- > 0) {
//            String visitingTimeStr = sdf.format(new Date(visitingTime));
//            System.out.println(visitingTimeStr);
//            visitingTime += 1000 * 60 * 60 * 24L;
//        }


//        final String ms = System.getenv("ms");
//        final String jdkAttach = System.getenv("jdk.attach.allowAttachSelf");
//        System.out.println(jdkAttach);
//
//
//        int count = 0;
//        Set<String> stSet = new HashSet<>();
//        for (int i = 0; i < 10000; i++) {
//            if (Math.random() * 100 <= 1) {
//                ++count;
//                stSet.add(String.valueOf(i));
//            }
//        }

//        System.out.println("total run count: " + count);
//        System.out.println("total run stSet: " + stSet.toString());
//        BufferedReader reader = new BufferedReader(new FileReader(new File("/Users/zhfan/Downloads/totalVI.csv")));
//        Set<String> totalVISet = new HashSet<>();
//        String line;
//        while (null != (line = reader.readLine())) {
//            if (StringUtils.isNotBlank(line)) {
//                try {
//                    totalVISet.add(line);
//                } catch (Exception e) {
//                }
//            }
//        }
//
//        reader = new BufferedReader(new FileReader(new File("/Users/zhfan/Downloads/342ee783-8a65-44f1-af6c-4e7ceb13a5fa.csv")));
//        Set<String> delivedVISet = new HashSet<>();
//        while (null != (line = reader.readLine())) {
//            if (StringUtils.isNotBlank(line)) {
//                try {
//                    String info = line.split("blocked vi : ")[1].split("status")[0];
//                    info = info.replace(" ", "");
//                    info = info.replace("|", "");
//
//                    if (delivedVISet.contains(info)) System.out.println("repeat vi : " + info);
//                    else delivedVISet.add(info);
//                } catch (Exception e) {
//                }
//            }
//        }
//
//        //输出start有，success 没有
//        for (String start : totalVISet) {
//            if (!delivedVISet.contains(start)) System.out.println("输出 totalVISet 有而 delivedVISet 没有: " + start);
//        }


//        BufferedReader reader = new BufferedReader(new FileReader(new File("/Users/zhfan/Downloads/download_documents/csv/start.csv")));
//        Set<String> startSendSet = new HashSet<>();
//        String line;
//        while (null != (line = reader.readLine())) {
//            if (StringUtils.isNotBlank(line)) {
//                try {
//                    String info = line.split("AutoEmailServiceImpl - current ")[1].split(", start to send email")[0];
//                    info = info.replace(" ", "");
//                    if (startSendSet.contains(info)) System.out.println("repeat start send: " + info);
//                    else startSendSet.add(info);
//                } catch (Exception e) {
//                }
//            }
//        }
//
//        reader.close();
//        reader = new BufferedReader(new FileReader(new File("/Users/zhfan/Downloads/download_documents/csv/finished.csv")));
//        Set<String> succeedSet = new HashSet<>();
//        while (null != (line = reader.readLine())) {
//            if (StringUtils.isNotBlank(line)) {
//                try {
//                    String info = line.split("AutoEmailServiceImpl - current ")[1].split(", has finished send email")[0];
//                    info = info.replace(" ", "");
//                    if (succeedSet.contains(info)) System.out.println("repeat succeed send: " + info);
//                    else succeedSet.add(info);
//                } catch (Exception e) {
//                }
//            }
//        }
//
//
//        reader.close();
//        reader = new BufferedReader(new FileReader(new File("/Users/zhfan/Downloads/download_documents/csv/inserted.csv")));
//        Set<String> insertDBSet = new HashSet<>();
//        while (null != (line = reader.readLine())) {
//            if (StringUtils.isNotBlank(line)) {
//                try {
//                    String info = line.split("AutoEmailServiceImpl - current ")[1].split(", had inserted to prepare for aut")[0];
//                    info = info.replace(" ", "");
//                    if (insertDBSet.contains(info)) System.out.println("repeat succeed send: " + info);
//                    else insertDBSet.add(info);
//                } catch (Exception e) {
//                }
//            }
//        }
//
//        //输出start有，success 没有
//        for (String start : startSendSet) {
//            if (!succeedSet.contains(start)) System.out.println("输出start有，success没有: " + start);
//        }
//
//        //输出success有，start没有
//        for (String suc : succeedSet) {
//            if (!startSendSet.contains(suc)) System.out.println("输出success有，start没有: " + suc);
//        }
//
//        //输出插入DB有，success没有
//        for (String insert : insertDBSet) {
//            if (!succeedSet.contains(insert)) {
//                if (insert.contains("type:illegal")) continue;
//                System.out.println("insert db current mis match: " + insert);
//            }
//        }


//        System.out.println(insertDBSet.toString());


//        // log.info("cannot get current sellerId: {}, type: {
//        }, ruleGroup :{}, mailTemplateId!",
//                "mailRecordVo.getVendorId()", null, null);


//        final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        for (int i = 0; i < 100; i++) {
//            System.out.println(i + " : " + df.format(new Date()));
//        }


//        StringBuilder uniqueKey = new StringBuilder();
//        uniqueKey.append("xx").append("_").
//                append("xx2").append("_").
//                append("null").append("_").
//                append("dt");


//        StringBuilder idStrBuilder = new StringBuilder();
//        idStrBuilder.append("12");
//        idStrBuilder.append(".");
//        idStrBuilder.append("34");
//        idStrBuilder.append(".");
//        idStrBuilder.append("56");
//        idStrBuilder.append(".");
//        idStrBuilder.append("78");
//        idStrBuilder.append(".");
//
//        if (idStrBuilder.length() > 0) idStrBuilder.delete(idStrBuilder.length() - 1, idStrBuilder.length());
//        System.out.println(idStrBuilder.toString());

//        String dt = "20210419";
//        final LocalDateTime localDateTime = parseDateFromString(dt);
//        System.out.println(formatLocalDatTime(localDateTime.minusDays(4), DateTimeFormatter.ofPattern("yyyyMMdd")));


//        LocalDate date=new LocalDate(convertToLocalDateTime(sdf.parse(dt)));
//        System.out.println(date.minusDays(4).toString());
//
//        System.out.println(Math.ceil(24.0000000001));


//        int curInsertStartPos = 0, curInsertEndPos = 0;
//        List<Integer> forInspectResultList = new ArrayList<>();
//        for (int i = 0; i < 100; i++) {
//            forInspectResultList.add(i);
//        }
//
//        while (curInsertStartPos < forInspectResultList.size()) {
//            curInsertEndPos = curInsertStartPos + SINGLE_BATCH_INSERT_SIZE > forInspectResultList.size() ? forInspectResultList.size() : curInsertStartPos + SINGLE_BATCH_INSERT_SIZE;
//            List<Integer> subInsertList = forInspectResultList.subList(curInsertStartPos, curInsertEndPos);
//            System.out.println(subInsertList.toString());
//            curInsertStartPos = curInsertEndPos;
//        }

//        File file = new File("/Users/zhfan/Downloads/download_documents/20210308_review");
//        // get the folder list
//        File[] array = file.listFiles();
//
//        for (int i = 0; i < array.length; i++) {
//            if (array[i].isFile()) {
//                // only take file name
//                System.out.println("file name: " + array[i].getName());
//            }
//        }


//        List<String> resultCandidate = Arrays.asList("a", "b");
//        for (int i = 0; i < 20; i++) {
//            System.out.println(resultCandidate.get(((int) (Math.random() * resultCandidate.size()))));
//        }


//        List<String> list = Arrays.asList("A", "B", "C", "D", "1", "2", "3");
//        List<Integer> sizeList = Arrays.asList(2, 3, 2);
//        int curAssignStartPos = 0;
//        for (int curAssignSize : sizeList) {
//            for (int i = curAssignStartPos; i < curAssignStartPos + curAssignSize; i++) {
//                System.out.println(list.get(i));
//            }
//            curAssignStartPos += curAssignSize;
//        }

//        //before shuffle
//        System.out.println(list);
//
//        // again, same insert order
//        System.out.println(list);
//
//        // shuffle or randomize
//        Collections.shuffle(list);
//        System.out.println(list);
//        System.out.println(list);
//
//        // shuffle again, different result
//        Collections.shuffle(list);
//        System.out.println(list);

    }

    public static final int SINGLE_BATCH_INSERT_SIZE = 7;

    public static String getListContent(List<String> list) {
        if (CollectionUtils.isEmpty(list)) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (String element : list) {
            sb.append(element).append("_");
        }

        return sb.delete(sb.length() - 1, sb.length()).toString();
    }

    /**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    public static void readFileByLines(String fileName, String outFileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            String conditionStr = "wxpay_mtgy_merchs={\n" +
                    "  \"10075427\": \"11000018954351\",\n" +
                    "  \"1227548002\": \"11000017190071\",\n" +
                    "  \"1228472902\": \"11000016590533\",\n" +
                    "  \"1230879202\": \"11000016248873\",\n" +
                    "  \"1240790602\": \"11000015931166\",\n" +
                    "  \"1249216901\": \"11000035035430\",\n" +
                    "  \"1252811001\": \"11000014422023\",\n" +
                    "  \"1259943701\": \"11000019540223\",\n" +
                    "  \"1270380901\": \"11000016250780\",\n" +
                    "  \"1275881301\": \"11000035030738\",\n" +
                    "  \"1284713701\": \"11000017181962\",\n" +
                    "  \"1299560801\": \"11000017829857\",\n" +
                    "  \"1299830701\": \"11000016247905\",\n" +
                    "  \"1299840901\": \"11000016587651\",\n" +
                    "  \"1304298701\": \"11000080136595\",\n" +
                    "  \"1305634201\": \"11000019539690\",\n" +
                    "  \"1316295501\": \"11000053322655\",\n" +
                    "  \"1345731201\": \"11000020111657\",\n" +
                    "  \"1359022502\": \"11000017190078\",\n" +
                    "  \"1378030302\": \"11000015750489\",\n" +
                    "  \"1401694002\": \"11000024613868\",\n" +
                    "  \"1411836002\": \"11000018941619\",\n" +
                    "  \"1429234802\": \"11000017255048\",\n" +
                    "  \"1429329902\": \"11000015751300\",\n" +
                    "  \"1436842702\": \"11000022903235\",\n" +
                    "  \"1439557702\": \"11000035032856\",\n" +
                    "  \"1442214702\": \"11000053324147\",\n" +
                    "  \"1486737262\": \"11000015746121\",\n" +
                    "  \"1500945761\": \"11000015914029\",\n" +
                    "  \"1505740901\": \"11000024900041\",\n" +
                    "  \"1507398901\": \"11000020106617\",\n" +
                    "  \"1508805021\": \"11000014424876\",\n" +
                    "  \"1509314401\": \"11000014426090\",\n" +
                    "  \"1509335721\": \"11000016251609\",\n" +
                    "  \"1509965341\": \"11000017249600\",\n" +
                    "  \"1510576621\": \"11000053323349\",\n" +
                    "  \"1511595231\": \"11000015750157\",\n" +
                    "  \"1512359741\": \"11000016590535\",\n" +
                    "  \"1519176721\": \"11000020107742\",\n" +
                    "  \"1519551061\": \"11000015910383\",\n" +
                    "  \"1519782871\": \"11000019532399\",\n" +
                    "  \"1523775141\": \"11000022909014\",\n" +
                    "  \"1530641711\": \"11000015930618\",\n" +
                    "  \"1535415341\": \"11000017257373\",\n" +
                    "  \"1535608261\": \"11000020106656\",\n" +
                    "  \"1540796991\": \"11000053323315\",\n" +
                    "  \"1548360681\": \"11000024894272\"\n" +
                    "}";


            /* 写入Txt文件 */
            File writename = new File(outFileName); // 相对路径，如果没有则要建立一个新的output。txt文件
            writename.createNewFile(); // 创建新文件
            BufferedWriter out = new BufferedWriter(new FileWriter(writename));

            // 一次读入一行，直到读入null为文件结束
            String name = null;
            String gyid = null;
            String oldMerchatId = null;
            String newMerchantId = null;
            String newSubMerchantId = null;
            String wxMerchantId = null;
            int unknownCount = 0;
            int configCount = 0;
            StringBuilder textOut = new StringBuilder();
            StringBuilder parentOut = new StringBuilder("{\n" +
                    "  \"11000023357629\": [\n" +
                    "    \"12000094640784\",\n" +
                    "    \"12000094640967\",\n" +
                    "    \"12000094639882\",\n" +
                    "    \"12000094639922\",\n" +
                    "    \"12000094202375\",\n" +
                    "    \"12000094202396\",\n" +
                    "    \"12000094202366\",\n" +
                    "    \"12000094642764\",\n" +
                    "    \"12000098755945\",\n" +
                    "    \"12000094202297\",\n" +
                    "    \"12000094202356\",\n" +
                    "    \"12000094202349\",\n" +
                    "    \"12000094202335\",\n" +
                    "    \"12000094202383\",\n" +
                    "    \"12000094202393\",\n" +
                    "    \"12000094202374\",\n" +
                    "    \"12000094202363\",\n" +
                    "    \"12000094202364\",\n" +
                    "    \"12000094202389\",\n" +
                    "    \"12000094202394\",\n" +
                    "    \"12000094202397\",\n" +
                    "    \"12000094202367\",\n" +
                    "    \"12000094202346\",\n" +
                    "    \"12000094202347\"\n");
            while (StringUtils.isNotBlank((name = reader.readLine()))) {
                gyid = reader.readLine();
                oldMerchatId = reader.readLine();
                newMerchantId = reader.readLine();
                newSubMerchantId = reader.readLine();
                wxMerchantId = reader.readLine();
                String lineStr = "";
                if (!"未知".equals(wxMerchantId) && conditionStr.contains(wxMerchantId) && conditionStr.contains(oldMerchatId)) {
                    ++configCount;
                    lineStr = "\n{\n\"pay_type\": \"26\",\n" +
                            "    \"pay_mode\": \"common\",\n" +
                            "    \"app_name\": \"11000023357629\",\n" +
                            "    \"old_biz_merch_no\": \"" +

                            oldMerchatId +

                            "\",\n" +
                            "    \"biz_merch_no\": \"11000023357629\",\n" +
                            "    \"biz_sub_merch_no\": \"" +
                            newSubMerchantId +
                            "\",\n" +
                            "    \"wx_merchant_id\": \"" +
                            wxMerchantId +
                            "\"\n" +
                            "  },";

                    lineStr += "\n{\n\"pay_type\": \"36\",\n" +
                            "    \"pay_mode\": \"common\",\n" +
                            "    \"app_name\": \"11000023357629\",\n" +
                            "    \"old_biz_merch_no\": \"" +

                            oldMerchatId +

                            "\",\n" +
                            "    \"biz_merch_no\": \"11000023357629\",\n" +
                            "    \"biz_sub_merch_no\": \"" +
                            newSubMerchantId +
                            "\",\n" +
                            "    \"wx_merchant_id\": \"" +
                            wxMerchantId +
                            "\"\n" +
                            "  },";


                    parentOut.append(",\"" + newSubMerchantId + "\"");
                    out.write(lineStr);
                    textOut.append("已配置的商户简称：" + name + ", 对应的新业务识别码（二级商户号）:"
                            + newSubMerchantId + "\n");
                } else {
                    ++unknownCount;
                    System.out.println("未配置的商户简称：" + name);
                }


            }

            parentOut.append("]\n" +
                    "}");
            out.write("\n\n\n\n" + parentOut.toString());
            reader.close();
            out.flush(); // 把缓存区内容压入文件
            out.close(); // 最后记得关闭文件

            System.out.println(textOut.toString());
            System.out.println("配置了：" + configCount);
            System.out.println("未配置：" + unknownCount);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }


    }


    public static void splitFile(String filePath, int splitSize) throws IOException {
        FileInputStream fis = new FileInputStream(filePath);
        FileChannel inputChannel = fis.getChannel();
        final long fileSize = inputChannel.size();
        long average = fileSize / splitSize;//平均值
        long bufferSize = 200; //缓存块大小，自行调整
        ByteBuffer byteBuffer = ByteBuffer.allocate(Integer.valueOf(bufferSize + "")); // 申请一个缓存区
        long startPosition = 0; //子文件开始位置
        long endPosition = average < bufferSize ? 0 : average - bufferSize;//子文件结束位置
        for (int i = 0; i < splitSize; i++) {
            if (i + 1 != splitSize) {
                int read = inputChannel.read(byteBuffer, endPosition);// 读取数据
                readW:
                while (read != -1) {
                    byteBuffer.flip();//切换读模式
                    byte[] array = byteBuffer.array();
                    for (int j = 0; j < array.length; j++) {
                        byte b = array[j];
                        if (b == 10 || b == 13) { //判断\n\r
                            endPosition += j;
                            break readW;
                        }
                    }
                    endPosition += bufferSize;
                    byteBuffer.clear(); //重置缓存块指针
                    read = inputChannel.read(byteBuffer, endPosition);
                }
            } else {
                endPosition = fileSize; //最后一个文件直接指向文件末尾
            }

            FileOutputStream fos = new FileOutputStream(filePath + (i + 1));
            FileChannel outputChannel = fos.getChannel();
            inputChannel.transferTo(startPosition, endPosition - startPosition, outputChannel);//通道传输文件数据
            outputChannel.close();
            fos.close();
            startPosition = endPosition + 1;
            endPosition += average;
        }
        inputChannel.close();
        fis.close();

    }

    public static void spilt(String from, int size, String to) throws IOException {
        File f = new File(from);
        FileInputStream in = new FileInputStream(f);
        FileOutputStream out = null;
        FileChannel inChannel = in.getChannel();
        FileChannel outChannel = null;

        // 将MB单位转为为字节B
        long m = size * 1024 * 1024;
        // 计算最终会分成几个文件
        int count = (int) (f.length() / m);
        // System.out.println(f.length() + " " + m + " " + count);
        for (int i = 0; i <= count; i++) {
            // 生成文件的路径
            String t = to + "/" + i + ".block";
            try {
                out = new FileOutputStream(new File(t));
                outChannel = out.getChannel();
                // 从inChannel的m*i处，读取固定长度的数据，写入outChannel
                if (i != count)
                    inChannel.transferTo(m * i, m, outChannel);
                else// 最后一个文件，大小不固定，所以需要重新计算长度
                    inChannel.transferTo(m * i, f.length() - m * count, outChannel);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                out.close();
                outChannel.close();
            }
        }
        in.close();
        inChannel.close();
    }

    public static void merge(String filePrefix, int splitCount, String mergedFileName) throws IOException {
        File mergedFile = new File(mergedFileName);
        FileInputStream in = null;
        FileChannel inChannel = null;

        FileOutputStream out = new FileOutputStream(mergedFile, true);
        FileChannel outChannel = out.getChannel();

        // 记录新文件最后一个数据的位置
        long start = 0;
        for (int i = 1; i <= splitCount; i++) {
            File file = new File(filePrefix + i);
            in = new FileInputStream(file);
            inChannel = in.getChannel();

            // 从inChannel中读取file.length()长度的数据，写入outChannel的start处
            outChannel.transferFrom(inChannel, start, file.length());
            start += file.length();
            in.close();
            inChannel.close();
        }

        out.close();
        outChannel.close();
    }


    CountDownLatch countDownLatch = new CountDownLatch(1);

    private void runThread() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    try {

                        countDownLatch.await();
                        System.out.println("Thread:" + Thread.currentThread().getName() + ",time: " + System.currentTimeMillis());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        countDownLatch.countDown();
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<Integer>();
        Stack<TreeNode> stack = new Stack<TreeNode>();
        while (root != null || !stack.empty()) {
            while (root != null) {
                stack.push(root);
                root = root.left;
            }
            if (!stack.isEmpty()) {
                root = stack.pop();
                res.add(root.val);
                root = root.right;
            }
        }

        return res;


//        List<Integer> list = new ArrayList<Integer>();
//        if (root == null) return list;
//
//        Stack<TreeNode> stack = new Stack<TreeNode>();
//        stack.push(root);
//        while (!stack.isEmpty()) {
//            TreeNode node = stack.peek();
//            while (node.left != null) {
//                stack.push(node.left);
//                node = node.left;
//            }
//
//            node = stack.pop();
//            list.add(node.val);
//            if (node.right != null) {
//                stack.push(node.right);
//            }
//
//        }
//
//        return list;
    }

//    public static void main(String[] args) throws Exception {
//
//
//        Runner an = new Runner();
//        TreeNode root = new TreeNode(1);
//        TreeNode a = new TreeNode(2);
//        TreeNode b = new TreeNode(3);
//        root.right = a;
//        a.left = b;
//
////        TreeNode root = TreeNode.createTree("1,null,2,3,null");
//
//
//        System.out.println(an.inorderTraversal(root));
//
////        String fileName = "/Users/vonmax/Downloads/input.txt";
////        String outName = "/Users/vonmax/Downloads/out.txt";
//
////        readFileByLines(fileName, outName);
//
////        long startTime = System.currentTimeMillis();
////        splitFileBySize("/Users/vonmax/Downloads/paygate_info.log-2020-05-22-2.log", 5);
////        long endTime = System.currentTimeMillis();
////        System.out.println("耗费时间： " + (endTime - startTime) + " ms");
//
//
////        merge("/Users/vonmax/Downloads/merge/paygate_info.log-2020-05-22-2.log", 5, "/Users/vonmax/Downloads/merge/final.txt");
////
////
////        Runner runner = new Runner();
////        runner.runThread();
//
//    }


    /**
     * parse the specified date to LocalDateTime
     *
     * @param dateStr format:yyyyMMdd
     * @return
     */
    public static LocalDateTime parseDateFromString(String dateStr) {
        return LocalDate.parse(dateStr, DateTimeFormatter.BASIC_ISO_DATE).atStartOfDay();
    }

    public static String formatLocalDatTime(LocalDateTime localDateTime, DateTimeFormatter formatter) {
        if (null == localDateTime || null == formatter) {
            return null;
        }
        return localDateTime.format(formatter);
    }

    public String readToString(String fileName) {
        String encoding = "UTF-8";
        File file = new File(fileName);
        Long filelength = file.length();
        byte[] filecontent = new byte[filelength.intValue()];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (Exception e) {
            // log.info("error!", e);
        }
        try {
            return new String(filecontent, encoding);
        } catch (Exception e) {
            System.err.println("The OS does not support " + encoding);
            e.printStackTrace();
            return null;
        }
    }


}
